import pyautogui
import os
import my_keys
import time
import utility
def destoryThing():
    (point,fileName) = utility.findOneFromDir("./images/uselessThings/",0.9)
    # fileList = os.listdir("./images/uselessThings")
    # for fileName in fileList:
    #     point = pyautogui.locateCenterOnScreen("./images/uselessThings/" + fileName,confidence=0.9)
    #     if point != None:
    #         break
    if point != None:
        my_keys.key_down(0x1d)
        my_keys.key_down(0x38)
        pyautogui.moveTo(point.x,point.y)
        time.sleep(0.5)
        pyautogui.click()
        my_keys.key_up(0x1d)
        my_keys.key_up(0x38)
        time.sleep(2)
        destoryThingCenter = pyautogui.locateCenterOnScreen("./images/uselessThings/" + fileName,confidence=0.9)
        destoryDialogRect = pyautogui.locateOnScreen("./images/destory_dialog.png",confidence=0.9)
        destoryOkButtonCenter = pyautogui.locateCenterOnScreen("./images/destory_ok.png",confidence=0.9)
        if (destoryOkButtonCenter != None) & (destoryThingCenter != None) & (destoryDialogRect !=None) & (destoryThingCenter.y < destoryDialogRect.top):
            pyautogui.click(destoryOkButtonCenter.x,destoryOkButtonCenter.y)
            time.sleep(2)
        else:
            print("执行销毁物品异常")
        return
